<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>History Test Page 3</title>
<script type="text/javascript" src="HistoryHelper.js"></script>
</head>

<body onload="onLoad();">
<div id="statusPanel" style="border: 1px solid red; width: 100%">
History Test Page 3....
</div>
</body>

<script type="text/javascript">

function onLoad() {
  if (readCookie(navigate_forward_cookie) != null) {
    setTimeout(OnNavigateForward, 0);
    return true;
  }
  if (readCookie(navigate_backward_cookie) != null) {
    setTimeout(OnNavigateBackward, 0);
    return true;
  }
  setTimeout(OnInitialLoad, 0);
  return true;
}

function OnInitialLoad() {
  // This page could be visited in the following sequences:-
  // 1. history_length_test_page2.html redirect to
  //    history_length_test_page3.html
  // 1. history_length_test_page1.html -> history_length_test_page2.html
  //    redirects to history_length_page3.html.
  // This history lengths could be 3 or 5.
  if (window.history.length != 3 && window.history.length != 4) {
    onFailure("History_Length_Test_2", 1,
              "History length mismatch on initial load at page 3: " +
              window.history.length);
    return false;
  }
  onSuccess("History_Length_Test_2", 1);
  return true;
}

function OnNavigateBackward() {
  if (window.history.length != 5) {
    onFailure("History_Length_Test_3", 1,
              "History length mismatch on navigating backward at page 3: " +
              window.history.length);
    return false;
  }
  window.history.back();
  return true;
}

function OnNavigateForward() {
  if (window.history.length != 5) {
    onFailure("History_Length_Test_3", 1,
              "History length mismatch on navigating forward at page 3: " +
              window.history.length);
    return false;
  }
  window.history.forward();
  return true;
}

</script>
</html>